package com.wang.exception_homework.hw1;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        test();
    }
    public static String test(){
        Scanner sc = new Scanner(System.in);
        try {
            System.out.println("请输入被除数：");
            int num1 = sc.nextInt();
            System.out.println("请输入除数：");
            int num2 = sc.nextInt();
            int num3 = num1 / num2;
            System.out.println("商为" + num3);
            return "执行try块中的return语句";
        } catch (ArithmeticException e) {
            System.err.println("出现错误：除数不能为零！");
            return "执行catch1块中的return语句";
        } catch (InputMismatchException e){
            System.out.println("出现错误：被除数和除数必须是整数!");
            return "执行catch2块中的return语句";
        } catch (Exception e){
            System.out.println("出现错误！");
            return "执行catch3块中的return语句";
        }
        finally {
            System.out.println("感谢使用本程序！");
        }
    }
}
